import Vue from 'vue'
import VueRouter from 'vue-router'

// 正常写法 -> 不会懒加载 -> 第一次就会加载的
import Login from '@/views/Login'
import Layout from '@/views/Layout'
import Home from '@/views/Home'

// 懒加载的写法 -> 当url与path匹配后，才会去加载对应的js和css文件
const User = () => import('@/views/User')
const Search = () => import('@/views/Search')
const ResultList = () => import('@/views/Search/ResultList')
const ArticleDetail = () => import('@/views/Article/id')
const UserEdit = () => import('@/views/User/Edit')
const Xiaoai = () => import('@/views/Xiaoai')

Vue.use(VueRouter)

const routes = [
  // 路由规则 我们 自己编写
  {
    path: '/',
    redirect: '/layout'// 重定向
  },
  { // 登录
    path: '/login',
    component: Login
  }, {
    path: '/layout',
    component: Layout,
    redirect: '/layout/home', // 重定向
    // 二级路由
    children: [
      { // 首页
        path: 'home',
        component: Home
      }, { // 用户
        path: 'user',
        component: User
      }
    ]
  }, { // 搜索
    path: '/search',
    component: Search
  }, { // 搜索结果
    path: '/search/:keyword',
    component: ResultList
  }, { // 文章详情
    // 这里我没用动态路由，目的是把路由的另外一种传参也练习一下
    path: '/article',
    component: ArticleDetail
  }, { // 用户编辑
    path: '/user/edit',
    component: UserEdit
  }, {
    path: '/xiaoai',
    component: Xiaoai
  }
]

const router = new VueRouter({
  routes
})

export default router
